Queue data structure: 

FIFO data structure
ADT: enqueue, dequeue, front, size, and isEmpty

Assumption: if there are n elements in the queue, they will occupy the first n positions in the array

Option#1: 
Let the front of the queue occupy the first position in the array
dequeue requires O(n) time
enqueue requires O(1) time

Option#2: 
Let the rear element be at index 0
enqueue requires O(n) time

To address the above limitations: 
1) Relax the assumption that the first n elements must occupy the first positions
=> drifting array
2) Introduce two new pointers: 
2.a) front: index of the front element ==> front = 0
2.b) rear: index of next available cell in the array ==> rear = 0

	rear front		
0	1	2
6	4	5

To address the above limitation where rear takes on an invalid index value: 
=> make the drifting array circular

front = (front + 1) % array.length
rear = (rear + 1) % array.length

To get the size of the queue, we will introduce a third variable: size

Plan:
1.a) Create the Queue ADT
1.b) Create the QueueException class
1.c) Create the ArrayBasedQueue
1.d) Test ArrayBasedQueue

2) Use it to solve the Josephus problem

Jeffrey, Khalil, Angela

Space complexity: O(n) where n is the number of players
Time complexity: O(nk) 

Josephus recurrence realtion:

J(n, k) the position of the winner when there are n players
J(n-1, k) the position of the winner when there are n - 1 players

J(n, k) = (J(n-1,k) + (k-1)) % n + 1

k = 1
n = 41 soldiers = 32 + 9 (L)
Position of the winner = 2*L + 1 = 2 * 9 + 1 = 19

-------------------------------------------------

Singly Linked list

LinkedList ---> doubly linked list


The majority of the data structures encountered so far ---> index-based
Linked list ---> position-based (nodes <---> positions)

head	     tail
  -next->   -next-> null
|	  |
e1 	  e2

Tail in a singly linked list is special node where next pointer = null

inerface Position<T> {
	T getElement();
}

SNode<T> class implementing the Position interface: T element + SNode<T> next

SinglyLinkedList<T>: SNode<T> head and SNode<T> tail + int size

















































